home *** CD-ROM | disk | FTP | other *** search
- /*
- File: AEDaemonMain.c
-
- Contains: This is a faceless background process who's whole mission in
- life is to send AppleEvents for code that can't (like the accompaning
- AECDEV). It will send any AppleEvent it gets through it's PPC port.
-
- The main things to note are....
- 1) Look at the SIZE resource for the flag settings you'll
- need to let the Finder™ know that you only want to work
- in the background.
- 2) Notice that you really do have your own heap and your own
- event loop. You can do anything a foreground application
- can do, send AppleEvents, PPC stuff, anything else you'd
- like EXCEPT a graphic interface.
- 3) NOTE that no managers are started up. You cannot start up
- Window, Menu, Dialogs, or anything else that
- deals with the graphic interface. Just leave them out.
- You CAN start up QuickDraw if you want to do some graphic
- processing, but DO NOT draw to the screen, only use things
- like offscreen grafports or GWorlds. Or you may
- want to start it to use Random().....
-
- Of course, a backgrounder can be launched from the Finder™
- with a double-click. However, if you'd like the backgrounder
- to perform some useful service for your main application, driver,
- DA, or whatever, you will want it running all the time.
- The BEST way to insure this is to install the backgrounder in the
- StartUp Items folder in the system folder. This will insure that
- it is always launched, and it will also reduce memory fragmentation
- since it will be installed at startup time. You can search for it
- when you need it with IPCListPorts (see the PPC toolbox documentation
- or the AECDEV code).
- Optionally, you can use the LaunchApplication trap to launch it
- when you need it, and kill it when you're done. But this could
- cause some multiFinder heap fragmentation.
-
- And remember, it's a backgrounder, you can't see it. To kill it
- use TaskIt or ProcDoggie.
-
- ---------------------------------------------------------------
- Use this sample as a starting point, and adapt its' routines to
- meet the specific needs of your project.
- This sample will grow as more edition types are implemented,
- periodically check AppleLink for a later, expanded sample.
- This application is an example of the form of a Macintosh
- application; it is NOT a template. It is NOT intended to be
- used as a foundation for the next world-class, best-selling,
- 600K application. A stick figure drawing of the human body may
- be a good example of the form for a painting, but that does not
- mean it should be used as the basis for the next Mona Lisa.
-
- Written by: C.K. Haun
-
- Copyright: Copyright © 1991-1999 by Apple Computer, Inc., All Rights Reserved.
-
- You may incorporate this Apple sample source code into your program(s) without
- restriction. This Apple sample source code has been provided "AS IS" and the
- responsibility for its operation is yours. You are not permitted to redistribute
- this Apple sample source code as "Apple sample source code" after having made
- changes. If you're going to re-distribute the source, we require that you make
- it clear in the source that the code was descended from Apple sample source
- code, but that you've made changes.
-
- Change History (most recent first):
- 7/20/1999 Karl Groethe Updated for Metrowerks Codewarror Pro 2.1
-
-
- */
-
-
- #include "AEDaemon.h"
-
- extern MyPPCRecPtrDeamon ourPPCPtr;
- extern Ptr readBuffer;
- extern Handle dataHandle;
- Boolean gQuit = false;
- EventRecord ERecord;
- Boolean gHasAppleEvents;
- Boolean gReadAgain;
- Boolean gReadPending;
- unsigned long gMySleep = 200; /* Long time. Change this if */
- /* you'd like to do null processing. Just keep in mind that the */
- /* user does NOT know that you exisist, and if you are eating */
- /* up a bunch of time the user will not know why his or her */
- /* machine is slowing down. */
-
- void main()
- {
- long ticksStart;
- /* We are NOT initializing any managers. We're in the background, with no */
- /* face, we can't use windows or dialogs or menus. If you need to talk to the */
- /* user you can post a notification, or launch an application to comunicate */
- /* Passing an AppleEvent in the launchapplication trap could do the */
- /* communication for you. */
-
- /* no nothing but events */
-
- InitAEStuff();
- /* now initialize our PPC connection so people know we're around */
- if(PPCInit() != noErr)ExitToShell(); /* bail */
- ourPPCPtr = (MyPPCRecPtrDeamon)NewPtrClear(sizeof(MyPPCRecDeamon));
- readBuffer = NewPtr(kOneK);
- dataHandle = NewHandle(nil); /* get an empty handle to start */
- /* check memory, bail if bad */
- if(ourPPCPtr == nil || dataHandle == nil || readBuffer== nil)ExitToShell();
- InformTheWorld();
- ticksStart = TickCount();
- /* no nothing but high level events */
- while (gQuit == false) {
- WaitNextEvent(highLevelEventMask, &ERecord, gMySleep, 0);
- if (ERecord.what == kHighLevelEvent)
- DoHighLevel(&ERecord);
- if (gReadPending)
- CollectLastData();
-
- }
- CloseOffTheWorld();
- }
-
- #undef __BUILDINGDEAMON__
- #undef __AEDMAIN__
-
-
-